public class demo02 {
    public static void main(String[] args) {
        Thread t=new Thread(()->{
            //currentThread是获取到当前线程实例（t）
            //isInterrupted是t对象里自带的一个标志位
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("hello 线程2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException ex) {
                        throw new RuntimeException(ex);
                    }
                    break;
                }
            }
        });

        t.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //将t内部的标志设置成true
        t.interrupt();
    }
}
